package com.zhang.crawler.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

/**
 * Copyright:   Copyright 2007 - 2017 MPR Tech. Co. Ltd. All Rights Reserved.
 * Date:        2017年09月06日 上午10:13
 * Author:      cncbox
 * Version:     1.0.0.0
 * Description: 分页结果类
 */

/**
 * 分页结果类
 */
@ApiModel(value = "分页结果类")
public class PaginationResponse<T> extends PaginationParameter {

    /**
     * 总共页数
     */
    @ApiModelProperty(value = "总共页数")
    private Integer pageSize;

    /**
     * 当前页数据
     */
    @ApiModelProperty(value = "当前页数据")
    private List<T> pageDataList;

    public List<T> getPageDataList() {
        return pageDataList;
    }

    public void setPageDataList(List<T> pageDataList) {
        this.pageDataList = pageDataList;
    }

    /**
     *
     * @param pagination 入参
     * @param size       总条数
     * @param data       结果集
     * @param <T>        结果集类型
     */
    public static <T> PaginationResponse<T> getPagination(PaginationParameter pagination, Long size,
                                                          List<T> data) {
        PaginationResponse<T> response = new PaginationResponse<>();
        response.setPageDataSize(size);
        response.setPageDataList(data);
        response.setPageOrder(pagination.getPageOrder());
        response.setPageIndex(pagination.getPageIndex());
        response.setPageRows(pagination.getPageRows());
        return response;
    }

    /**
     *
     * @param pagination 入参
     * @param size       总条数
     * @param data       结果集
     * @param pages      总页数
     * @param <T>        结果集类型
     */
    public static <T> PaginationResponse<T> getPagination(PaginationParameter pagination, Long size,
                                                          List<T> data, Integer pages) {
        PaginationResponse<T> response = new PaginationResponse<>();
        response.setPageDataSize(size);
        response.setPageDataList(data);
        response.setPageOrder(pagination.getPageOrder());
        response.setPageIndex(pagination.getPageIndex());
        response.setPageRows(pagination.getPageRows());
        response.setPageSize(pages);
        return response;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
}
